home *** CD-ROM | disk | FTP | other *** search
- /* See license.txt for terms of usage */
-
- /**
- * CDblClicker
- * ----------------------------------------
- * @Object for controlling double-clicks...
- * @bYO!
- */
-
- window.addEventListener("load", function(e) { CDblClicker.onLoad(e); }, false);
-
- /**
- * @constructor
- */
-
- const CDblClicker = new function(){
- // macro replacement...
- const _bDebug = false;
- function TRACE(s)
- {
- if (_bDebug)
- dump("####### " + s + " #######\n");
- };
-
- const _spClickDelay = 250;
- var m_bInterClick = false;
- var m_eClicked = null;
-
- return {
-
- onLoad: function (aEvent)
- { // initialization code gBrowser.onTabBarDblClick = this.onTabBarDblClick;
- gBrowser.mTabContainer.addEventListener("dblclick", this.onTabBarDblClick, true);
- window.addEventListener("click",this.onHandleClick,true);
- window.addEventListener("mouseup",this.onHandleMouseup,true);
- this.initialized = true;
- },
-
- onTabBarDblClick: function (aEvent)
- {
- //TRACE("onTabBarDblClick: - in " + aEvent.target.localName );
- if (aEvent.target.localName!="tab" || aEvent.button!=0 || aEvent.ctrlKey || aEvent.shiftKey || aEvent.altKey || aEvent.metaKey)
- return;
- var nAction = gBrowser.mPrefs.getIntPref("extensions.dblclicker.dblclicktab")
- switch ( nAction )
- {
- case 1: var tTab = gBrowser.duplicateTab(gBrowser.selectedTab);
- gBrowser.selectedTab = tTab;
- killEvent(aEvent);
- break;
- case 2: gBrowser.removeCurrentTab();
- killEvent(aEvent);
- }
- },
-
- onHandleMouseup: function (aEvent)
- {
- //TRACE("onHandleMouseup: - in " + aEvent.detail );
- if (m_bInterClick || aEvent.button!=0 || aEvent.ctrlKey || aEvent.shiftKey || aEvent.altKey || aEvent.metaKey)
- {
- //TRACE("onHandleMouseup: !pure - out");
- m_bInterClick = false;
- m_eClicked = null;
- return;
- }
- var target = aEvent.originalTarget;
- if (target.localName != "menuitem" || !target.node || !PlacesUtils.nodeIsURI(target.node))
- return;
-
- if (aEvent.detail==1)
- {
- m_eClicked = aEvent.target;
- killEvent(aEvent);
- setTimeout(function(){ doMouseup(target, aEvent);}, _spClickDelay);
- return;
- }
- if (aEvent.detail==2)
- {
- killEvent(aEvent);
- var windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
- // windowUtils.sendMouseEvent("mousedown", aEvent.clientX, aEvent.clientY, 0, 1, Ci.nsIDOMNSEvent.CONTROL_MASK);
- windowUtils.sendMouseEvent("mouseup", aEvent.clientX, aEvent.clientY, 0, 1, Ci.nsIDOMNSEvent.CONTROL_MASK);
- return;
- }
- //TRACE("onHandleMouseup: - out " + aEvent.detail );
- },
-
- onHandleClick: function (aEvent)
- {
- //TRACE("onHandleClick: - in " + aEvent.detail );
- if (m_bInterClick || aEvent.button!=0 || aEvent.ctrlKey || aEvent.shiftKey || aEvent.altKey || aEvent.metaKey)
- {
- //TRACE("onHandleClick: !pure - out");
- m_bInterClick = false;
- m_eClicked = null;
- return;
- }
- if (aEvent.target instanceof HTMLElement)
- {
- if (aEvent.detail==1)
- onClickDoc(aEvent);
- else
- if (aEvent.detail==2)
- onDblClick(aEvent, false);
- return;
- }
- if (aEvent.originalTarget.localName == "treechildren")
- {
- if (aEvent.detail==1)
- onClickTree(aEvent);
- else
- if (aEvent.detail==2)
- onDblClick(aEvent, true);
- return;
- }
- }
- };
-
- function onClickTree(aEvent)
- {
- //TRACE("onTreeClick: id - " + aEvent.originalTarget.localName);
- m_eClicked = null;
- var tbo = aEvent.originalTarget.parentNode.boxObject;
- if (!(tbo.view instanceof Ci.nsINavHistoryResultTreeViewer))
- return;
-
- var row = { }, col = { }, obj = { };
- tbo.getCellAt(aEvent.clientX, aEvent.clientY, row, col, obj);
- if (row.value == -1 || obj.value == "twisty" || tbo.view.isContainer(row.value))
- {
- //TRACE("onTreeClick: na/twisty/container - out");
- return;
- } // check ingutter
- var mouseInGutter = false;
- var x = { }, y = { }, w = { }, h = { };
- tbo.getCoordsForCellItem(row.value, col.value, "image", x, y, w, h);
- mouseInGutter = aEvent.clientX < x.value;
- if (mouseInGutter)
- return;
-
- var eClicked = tbo.view.nodeForTreeIndex(row.value);
- if (!PlacesUtils.nodeIsURI(eClicked))
- return;
- //TRACE("onTreeClick: - Suspend Click");
- m_eClicked = eClicked;
- killEvent(aEvent);
- var aEvt = cloneEvent(aEvent, false);
- var aObj = aEvent.originalTarget;
- setTimeout(function(){ doClick(aObj, aEvt, true);}, _spClickDelay);
- };
-
- function onClickDoc(aEvent)
- {
- //TRACE("onDocClick: - in " + aEvent.target);
- m_eClicked = null;
- // only links... form browser.js
- var target = aEvent.target;
- var linkNode;
-
- if (target instanceof HTMLAnchorElement ||
- target instanceof HTMLAreaElement ||
- target instanceof HTMLLinkElement) {
- if (target.hasAttribute("href"))
- linkNode = target;
-
- var parent = target.parentNode;
- while (parent) {
- if (parent instanceof HTMLAnchorElement ||
- parent instanceof HTMLAreaElement ||
- parent instanceof HTMLLinkElement) {
- if (parent.hasAttribute("href"))
- linkNode = parent;
- }
- parent = parent.parentNode;
- }
- }
- else {
- linkNode = aEvent.originalTarget;
- while (linkNode && !(linkNode instanceof HTMLAnchorElement))
- linkNode = linkNode.parentNode;
- if (linkNode && !linkNode.hasAttribute("href"))
- linkNode = null;
- }
- if (!linkNode)
- return;
- //TRACE("onDocClick: - Suspend Click");
- m_eClicked = linkNode;
- killEvent(aEvent);
- var aEvt = cloneEvent(aEvent, false);
- setTimeout(function() { doClick(target, aEvt, false);}, _spClickDelay);
- };
-
- function onDblClick(aEvent, bTree)
- {
- //TRACE("onDblClick: - in");
- if (!m_eClicked)
- return;
-
- killEvent(aEvent);
- eEvt = cloneEvent(aEvent, true);
- m_bInterClick = true;
- var b = aEvent.originalTarget.dispatchEvent(eEvt);
- //TRACE("onDblClick: - dispatchEvent res: " + b);
- if ( bTree && gBrowser.mPrefs.getBoolPref("extensions.dblclicker.closesidebar") )
- setTimeout(function(){ toggleSidebar(); }, 150);
- };
-
- function doMouseup(aObj, aEvt)
- {
- //TRACE("doClick: - in");
- if (!m_eClicked)// there was dclick...
- return;
-
- m_bInterClick = true;
- var windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
- windowUtils.sendMouseEvent(aEvt.type, aEvt.clientX, aEvt.clientY, 0, 1, 0);
- };
-
- function doClick(aObj, aEvt, bTree)
- {
- //TRACE("doClick: - in");
- if (!m_eClicked)// there was dclick...
- return;
-
- m_bInterClick = true;
- aObj.dispatchEvent(aEvt);
- if ( bTree && gBrowser.mPrefs.getBoolPref("extensions.dblclicker.closesidebar") )
- toggleSidebar();
- };
-
- function cloneEvent(aEvent, ctrlKey)
- {
- var tmp = document.createEvent ("MouseEvents");
- tmp.initMouseEvent ("click", true, true, aEvent.view, 1 /*aEvent.detail*/, aEvent.screenX, aEvent.screenY, aEvent.clientX, aEvent.clientY,
- ctrlKey, aEvent.altKey, aEvent.shiftKey, aEvent.metaKey, aEvent.button, aEvent.relatedEventTarget);
- return tmp;
- };
-
- function killEvent(aEvent)
- {
- aEvent.preventDefault();
- aEvent.stopPropagation();
- };
- };